package com.elm_springboot_s.mapper;

import com.elm_springboot_s.pojo.DeliveryAddress;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeliveryAddressMapper {
    
    @Select("SELECT * FROM deliveryaddress WHERE userId = #{userId}")
    List<DeliveryAddress> listDeliveryAddressByUserId(Long userId);
    
    @Select("SELECT * FROM deliveryaddress WHERE daId = #{daId}")
    DeliveryAddress getDeliveryAddressById(Integer daId);
    
    @Insert("INSERT INTO deliveryaddress (contactName, contactSex, contactTel, address, userId) " +
            "VALUES (#{contactName}, #{contactSex}, #{contactTel}, #{address}, #{userId})")
    int saveDeliveryAddress(String contactName, Integer contactSex, String contactTel, 
                          String address, Long userId);
    
    @Update("UPDATE deliveryaddress SET contactName = #{contactName}, contactSex = #{contactSex}, " +
            "contactTel = #{contactTel}, address = #{address}, userId = #{userId} " +
            "WHERE daId = #{daId}")
    int updateDeliveryAddress(Integer daId, String contactName, Integer contactSex, 
                            String contactTel, String address, Long userId);
    
    @Delete("DELETE FROM deliveryaddress WHERE daId = #{daId}")
    int removeDeliveryAddress(Integer daId);
} 